package impl.persons;

import framework.Business;
import framework.PersonAdapter;
import org.apache.log4j.Logger;

import java.util.HashMap;
import java.util.Map;

/** Implements "GRIM trigger" personal strategy. */
public class Trigger extends PersonAdapter {
    static Logger LOG = Logger.getLogger(Trigger.class);
    private Map<Object, Boolean> flag = new HashMap<Object, Boolean>();

    @Override
    public String getShortName() {
        return "GRIM";
    }

    @Override
    public int deal(Object id) {
        if (flag.containsKey(id)) {
            return Business.DEFECT;
        }
        return Business.COOPERATE;
    }

    @Override
    public void dealed(Object id, int deal) {
        if (deal == Business.DEFECT) {
            flag.put(id, Boolean.TRUE);
        }
    }
}